<template>
  <div>
    <basic-container>
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>广告配置</el-breadcrumb-item>
        <el-breadcrumb-item>版本配置克隆</el-breadcrumb-item>
      </el-breadcrumb>
    </basic-container>
    <div style="margin: 20px 10px">
      <el-radio-group v-model="select" size="medium">
        <el-radio-button label="1">自动选择</el-radio-button>
        <el-radio-button label="2">手动输入</el-radio-button>
      </el-radio-group>
    </div>
    <basic-container>
      <el-form :inline="true" :model="form" class="demo-form-inline">
        <el-form-item label="待克隆配置">
          <el-select v-model="form.type" placeholder="待克隆配置">
            <el-option label="广告位id设置" value="1"></el-option>
            <!-- <el-option label="开屏广告启动间隔时间" value="2"></el-option> -->
            <el-option label="阅读器广告页数配置" value="3"></el-option>
            <!-- <el-option
              label="阅读器底部banner更新间隔时间"
              value="4"
            ></el-option> -->
            <!-- <el-option label="阅读器广告强制停留时间" value="5"></el-option>
            <el-option label="AI听书" value="6"></el-option>
            <el-option label="自动阅读" value="7"></el-option>
            <el-option label="阅读免广告" value="8"></el-option>
            <el-option label="渠道免广告" value="9"></el-option>
            <el-option label="功能开关" value="10"></el-option> -->
            <el-option label="新用户渠道跳转" value="11"></el-option> 
            <el-option label="开始展示广告章节配置" value="12"></el-option>
            <el-option label="广告展示配置" value="13"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="copy版本">
          <!-- 输入 -->
          <el-input
            v-model="form.old_version"
            placeholder="输入copy版本"
            v-if="select != 1"
          ></el-input>
          <!-- 选择 -->
          <el-select v-model="form.old_version" placeholder="选择copy版本" v-else>
            <el-option
              v-for="item in versionList"
              :key="item.value"
              :label="item.app_version"
              :value="item.app_version"
            >
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="指向版本">
          <!-- 输入 -->
          <el-input
            v-model="form.new_version"
            placeholder="输入指向版本"
            v-if="select != 1"
          ></el-input>
          <!-- 选择 -->
          <el-select v-model="form.new_version" placeholder="选择指向版本" v-else>
            <el-option
              v-for="item in versionList"
              :key="item.value"
              :label="item.app_version"
              :value="item.app_version"
            >
            </el-option>
          </el-select>

        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">克隆</el-button>
        </el-form-item>
      </el-form>
    </basic-container>
  </div>
</template>

<script>
import { copy } from "@/api/cat/ad";
import { selectVersion as version } from "@/api/cat/baseUrls";
import { common } from "@/api/cat/httpRequest";

export default {
  data() {
    return {
      form: {
        type: "",
        old_version: "",
        new_version: "",
      },
      select: "1",
      versionList: [],
    };
  },
  methods: {
    async onSubmit() {
      //判断参数
      let {type,old_version,new_version} = this.form
      let regex = /\S/g
      if(!(regex.test(type)&&regex.test(old_version)&&regex.test(new_version))){
          this.$message.error('请完善参数')
      }
      if(old_version==new_version){
          this.$message.error('版本相同无法克隆')
      }
      let res = await copy(this.form);
      console.log(res);
      //   this.$message.success(this.form);
    },
  },
  //查询版本
  async created() {
    let { data } = await common(`${version.baseUrl}`, null, null, "GET");
    this.versionList = data;
  },
};
</script>

<style>
</style>